using System.Threading.Tasks;

namespace GetKlient.handle
{
    public class GetData
    {
        public string BaseUrl = "http://dev.meirenji.cn/";
        public string ContentType = "application/x-www-form-urlencoded";
        public async Task<Models.Token?> GetToken(string grantType, string clientID, string clientSecret)
        {
            string url = BaseUrl + "oauth/token";
            string payload = $"grant_type={grantType}&client_id={clientID}&client_secret={clientSecret}";
            return await utils.HttpHelper.MakeRequest<Models.Token>(url, payload, ContentType);
        }

        public async Task<Models.Instances?> GetOpenId(string appID,string accessToken)
        {
            string url =  BaseUrl + "api/v2/instances";
            string payload = $"appid={appID}&access_token={accessToken}";
            return await utils.HttpHelper.MakeRequest<Models.Instances>(url, payload, ContentType);
        }

        public async Task<Models.Detail?> GetDetail(string appID,string accessToken,string openId)
        {
            string url = BaseUrl + "api/v2/instance/detail";
            var payload = $"access_token={accessToken}&appId={appID}&openId={openId}";
            return await utils.HttpHelper.MakeRequest<Models.Detail>(url, payload, ContentType);
        }
         public static async Task<Models.InOutData?> GetInOut(string appID, string accessToken, string openId, string passagewayId, string tim)
        {
            string url = "http://dev.meirenji.cn/api/v2/passageway/traffic/five";
            string payload = $"access_token={accessToken}&appId={appID}&openId={openId}&passagewayId={passagewayId}&start={tim}&end={tim}";
            return await utils.HttpHelper.MakeRequest<Models.InOutData>(url, payload, "application/x-www-form-urlencoded");
        }
    }
    
}